package cn.edu.sgu.www.mhxysy.controller.jingmai;

import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.dto.jingmai.JingmaiPointDTO;
import cn.edu.sgu.www.mhxysy.entity.jingmai.JingmaiPoint;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.jingmai.JingmaiPointService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "角色经脉点管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@Validated
@RestController
@RequestMapping(path = "/jingmai_point", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class JingmaiPointController {

    private final JingmaiPointService jingmaiService;

    @Autowired
    public JingmaiPointController(JingmaiPointService jingmaiService) {
        this.jingmaiService = jingmaiService;
    }

    @ApiOperation("添加角色经脉点")
    @ApiOperationSupport(ignoreParameters = "id")
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public JsonResult<Void> insert(@Validated JingmaiPointDTO jingmaiPointDTO) {
        jingmaiService.insert(jingmaiPointDTO);

        return JsonResult.success(CustomMessages.INSERT_SUCCESS);
    }

    @ApiOperation("镶嵌星辰晶石")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stoneId", value = "星辰晶石ID", required = true),
            @ApiImplicitParam(name = "jingmaiId", value = "经脉类型IDID", required = true)
    })
    @RequestMapping(value = "/inlayStone", method = RequestMethod.POST)
    public JsonResult<Void> inlayStone(
            @NotBlank(message = "星辰晶石" + CustomMessages.ID_NOT_NULL) String stoneId,
            @NotNull(message = "经脉类型" + CustomMessages.ID_NOT_NULL) Integer jingmaiId) {
        jingmaiService.inlayStone(stoneId, jingmaiId);

        return JsonResult.success(CustomMessages.OPERATE_SUCCESS);
    }

    @ApiOperation("通过角色ID查询经脉点列表")
    @RequestMapping(value = "/selectByRoleId", method = RequestMethod.GET)
    public JsonResult<List<JingmaiPoint>> selectByRoleId(
            @ApiParam(name = "roleId", value = "角色ID", required = false)
            @RequestParam(required = false) String roleId) {
        List<JingmaiPoint> list = jingmaiService.selectByRoleId(roleId);

        return JsonResult.success(null, list);
    }

}